package cn.yili12.business.service;

import cn.yili12.business.entity.OrganizeDb;
import cn.yili12.business.repository.OrganizeRepository;
import cn.yili12.common.util.IdTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class OrganizeService {
    @Autowired
    private OrganizeRepository repository;
    @Autowired
    private IdTool idTool;


    public OrganizeDb save(OrganizeDb organizeDb) {
        organizeDb.setId(idTool.createId());
        return repository.save(organizeDb);
    }

    public Page<OrganizeDb> findAll(Integer pageNumber, Integer pageSize) {
        Pageable pageable = PageRequest.of(pageNumber - 1, pageSize);
        Example<OrganizeDb> example = Example.of(new OrganizeDb());
        return repository.findAll(example, pageable);
    }


    public void delete(Long id) {
        repository.deleteById(id);
    }


    public OrganizeDb get(Long id){
        return repository.getOne(id);
    }

}
